﻿using System.Collections.Generic;
using System.Linq;
using Citi.Scheduler.Domain.Utils;

namespace Citi.Scheduler.Domain
{
    public partial class LibraryVersion
    {
        public enum LibraryStatus
        {
            Error = 0,
            UnderCorrection = 1,
            Ok = 2,
            NoFile = 3,
            InvalidDll = 4
        }

        public IEnumerable<LibraryVersion> GetByLibraryId(int libraryId)
        {
            return Context.Instance.LibraryVersions.Where(x => x.LibraryId == libraryId);
        }

        public LibraryVersion GetLastByLibraryIdAndType(int libraryId, int type)
        {
            return GetByLibraryIdAndType(libraryId, type).FirstOrDefault();
        }

        public IEnumerable<LibraryVersion> GetByLibraryIdAndType(int libraryId, int type)
        {
            return GetByLibraryId(libraryId).Where(x => x.Type == type).OrderByDescending(x => x.Date);
        }

        public IEnumerable<LibraryVersion> GetValidsByLibraryIdAndType(int libraryId, int type)
        {
            return GetByLibraryIdAndType(libraryId, type).Where(x => x.Status == (int)LibraryStatus.Ok);
        }
    }
}
